package response

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

//用于封装返回
//{  通常希望的返回格式如下
//	"code":200
//	"data":{},
//	"msg":xxx
//}

func Response(ctx *gin.Context, httpStatus int, code int, data gin.H, msg string)  {
	ctx.JSON(httpStatus,gin.H{"code":code,"data":data,"msg":msg})
	//http状态码是TCP通信识别用的，JSON格式的状态码是客户端识别用的（也就是我自己业务层面的标识码）
}

func Success(ctx *gin.Context,data gin.H,msg string)  { //成功的
	Response(ctx,http.StatusOK,200, data, msg)
}

func Fail(ctx *gin.Context,data gin.H,msg string)  { //成功的
	Response(ctx,http.StatusOK,400, data, msg)
}